package com.yh.service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.yh.dao.UserDao;
import com.yh.db.SqlSessionFactoryUtil;
import com.yh.entity.User;
import com.yh.service.UserService;

public class UserServiceImpl implements UserService {

	@Override
	public boolean deleteUserById(int u_id) {
		// TODO 自动生成的方法存根
		
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		UserDao userDao = sqlSession.getMapper(UserDao.class);
		int record = userDao.deleteUserById(u_id);
		sqlSession.commit();
		sqlSession.close();
		if(record>0){
			return true;
		}
		return false;
	}

	@Override
	public User queryUserById(int u_id) {
		// TODO 自动生成的方法存根
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		UserDao userDao = sqlSession.getMapper(UserDao.class);
		User user = userDao.queryUserById(u_id);
		sqlSession.close();
		return user;
	}

	@Override
	public List<User> getUserList() {
		// TODO 自动生成的方法存根
		return null;
	}

	@Override
	public boolean updateUserById(User user) {
		// TODO 自动生成的方法存根
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		UserDao userDao = sqlSession.getMapper(UserDao.class);
		int record = userDao.updateUserById(user);
		sqlSession.commit();
		sqlSession.close();
		if(record > 0){
			return true;
		}
		return false;
	}

	

}
